package com.huajx.tuopuda.client.udp.codec.record;

import com.huajx.tuopuda.client.udp.TuopudaDirect;
import com.huajx.tuopuda.client.udp.TuopudaUtil;
import com.huajx.tuopuda.client.udp.codec.AbstractCodec;

/**
 * 读取指定索引位的记录信息[108D]
 *
 * @author: lisa 叶新华
 * @create: 2019-09-28 19:11
 */
public class ReadRecordCodec extends AbstractCodec {
    private int function = TuopudaDirect.D_108d;

    private int index;

    protected ReadRecordCodec(int sn, int index) {
        setSn(sn);
        this.index = index;
    }

    public static ReadRecordCodec getInstance(int sn, int index) {
        return new ReadRecordCodec(sn, index);
    }

    @Override
    public byte[] encode() {
        return encode(getSn(), getFunction(), bytes -> TuopudaUtil.replaceBytes(bytes, getIndex(), 5, 4));
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getFunction() {
        return function;
    }

    protected void setFunction(int function) {
        this.function = function;
    }
}
